<meta charset="<?= getMessageByKey("default.charset") ?>">

<?php
if (!init()) {
  redirect("?action=login");
}

?>


<div class="maincommon">

<?php
include_once("profile_menu.php");
?>

<div class="profilesectionheader">
  <?= getMessageByKey('user.profile.settings')?>
</div>
<?php

$usrGroupsSet = getUserGroups();
$otherGroupsSet = getOtherGroups();

$userGroupsArray = array();

?>
<div class="userinfodiv">
  <div class="header">
    <?= getMessageByKey("user.profile.groups.header") ?>
  </div>
  <?php while ($usrGroup = mysql_fetch_assoc($usrGroupsSet)) {
    array_push($userGroupsArray, $usrGroup['id']);
    ?>
    <div class="groupdiv">
      <div class="header">
        <?= $usrGroup['header'] ?>
      </div>
      <div class="td">
        <?= getMessageByKey("user.profile.groups.group.header") ?> <?= $usrGroup['header'] ?>
      </div>
      <div class="td">
        <?= getMessageByKey("user.profile.groups.members") ?> <?= countGroupMembers($usrGroup['id']) ?>
      </div>
    </div>
  <?php
  }
  ?>


  <div class="header">
    <?= getMessageByKey("user.profile.groups.other.header") ?>
  </div>
  <?php while ($otherGroup = mysql_fetch_assoc($otherGroupsSet)) {
    if (!in_array($otherGroup['id'], $userGroupsArray)) {
      ?>
      <div class="othergroupdiv">
        <div class="header">
          <?= $otherGroup['header'] ?>
        </div>
        <div class="td">
          <?= getMessageByKey("user.profile.groups.group.header") ?> <?= $otherGroup['header'] ?>
        </div>
        <div class="td">
          <?= getMessageByKey("user.profile.groups.members") ?> <?= countGroupMembers($otherGroup['id']) ?>
        </div>
      </div>
      <?php
      if (!isWaitingForGroup($otherGroup['id'])) {
        ?>
        <div class="othergroupbutton"
             onclick="location.href='?action=profgrent&gid=<?= $otherGroup['id'] ?>'">
          <?= getMessageByKey("user.profile.groups.enter") ?>
        </div>
      <?php
      } else {
        ?>
        <div class="othergroupbutton">
          <?= getMessageByKey("user.profile.groups.processing") ?>
        </div>
      <?php
      }
    }
  }
  ?>
</div>


<div class="userinfodiv">
  <form action="?action=profinfohand" method="POST" accept-charset="UTF-8" id="infoform">
    <div class="header">
      <?= getMessageByKey("user.profile.info.header") ?>
    </div>
    <?php
    $user = getUserInfo($_SESSION['id']);
    ?>
    <div class="tr">
      <div class="td">
        <?= getMessageByKey("user.profile.info.nick") ?>
      </div>
      <div class="td">
        <input type="text" maxlength="20" required="true" name="nick"
               value="<?= $user['nick'] ?>">
      </div>
    </div>
    <input type="hidden" name="oldnick" value="<?= $user['nick'] ?>">
    <input type="hidden" name="oldmail" value="<?= $user['email'] ?>">

    <div class="tr">
      <div class="td">
        <?= getMessageByKey("user.profile.info.firstname") ?>
      </div>
      <div class="td">
        <input type="text" maxlength="50" required="true" name="firstname"
               value="<?= $user['firstname'] ?>">
      </div>
    </div>
    <div class="tr">
      <div class="td">
        <?= getMessageByKey("user.profile.info.lastname") ?>
      </div>
      <div class="td">
        <input type="text" maxlength="50" required="true" name="lastname"
               value="<?= $user['lastname'] ?>">
      </div>
    </div>
    <div class="tr">
      <div class="td">
        <?= getMessageByKey("user.profile.info.email") ?>
      </div>
      <div class="td">
        <input type="text" maxlength="40" required="true" name="email"
               value="<?= $user['email'] ?>">
      </div>
    </div>
    <div class="tr">
      <div class="td">
        <?= getMessageByKey("user.profile.info.icq") ?>
      </div>
      <div class="td">
        <input type="text" maxlength="20" required="true" name="icq"
               value="<?= $user['icq'] ?>">
      </div>
    </div>

    <div class="tr">
      <div class="td">
        <?= getMessageByKey("user.profile.info.skype") ?>
      </div>
      <div class="td">
        <input type="text" maxlength="10" required="true" name="skype"
               value="<?= $user['skype'] ?>">
      </div>
    </div>

    <div class="tr">
      <div class="td">
        <?= getMessageByKey("user.profile.info.mobile") ?>
      </div>
      <div class="td">
        <input type="text" maxlength="20" required="true" name="mobile"
               value="<?= $user['mobile'] ?>">
      </div>
    </div>

    <div class="tr">
      <div class="td">
        <?= getMessageByKey("user.profile.info.address") ?>
      </div>
      <div class="td">
        <input type="text" maxlength="40" required="true" name="address"
               value="<?= $user['address'] ?>">
      </div>
    </div>

    <div class="tr">
      <div class="td">
        <?= getMessageByKey("user.profile.info.methods") ?>
      </div>
      <div class="td">
        <input type="text" maxlength="20" required="true" name="methods"
               value="<?= $user['methods'] ?>">
      </div>
    </div>

    <div class="tr">
      <div class="td">
        <?= getMessageByKey("user.profile.info.birth") ?>
      </div>
      <div class="td">
        <input type="date" maxlength="10" required="true" name="birth"
               value="<?= $user['birth'] ?>">
      </div>
    </div>


    <div class="button" onclick="$('#infoform').submit()">
      <?= getMessageByKey("button.general.continue") ?>
    </div>
  </form>
</div>


<?php

$usrVis = getUserVisibility();
$galVis = getGalleryVisibility();
$usrDel = isWaitingForDelete();

?>

<div class="usersettingsdiv">
  <form action="?action=profpasshand" method="post" id="passchangeform">
    <div class="header">
      <?= getMessageByKey("user.settings.pass.change") ?>
    </div>
    <div class="tr">
      <div class="td">
        <?= getMessageByKey("pass.old") ?>
      </div>
      <div class="td">
        <input type="password" maxlength="20" required name="oldpass">
      </div>
    </div>
    <div class="tr">
      <div class="td">
        <?= getMessageByKey("pass.new") ?>
      </div>
      <div class="td">
        <input type="password" maxlength="20" required name="pass1">
      </div>
    </div>
    <div class="tr">
      <div class="td">
        <?= getMessageByKey("pass.repeat") ?>
      </div>
      <div class="td">
        <input class="updateuserinfoinput" type="password" maxlength="20" required name="pass2">
      </div>
    </div>
    <div class="button" onclick="$('#passchangeform').submit()">
      <?= getMessageByKey("button.general.change") ?>
    </div>
  </form>
</div>

<form action="?action=profdelusrhand" style="display: <?php

if ($usrDel != 0) {
  echo "none";
} else echo "block";

?>" method="post" id="usrdelform">
  <div class="usersettingsdiv">
    <div class="header">
      <?= getMessageByKey("user.settings.profile.delete") ?>
    </div>
    <div class="deletebutton" onclick="$('#del').slideDown()">
      <?= getMessageByKey("button.general.delete") ?>
    </div>
    <div class="askdeletebuttonsdiv" style="display: none;" id="del">
      <?= getMessageByKey("user.settings.profile.drop.ask") ?><br>

      <div class="button" onclick="$('#usrdelform').submit()">
        <?= getMessageByKey("general.yes") ?>
      </div>
      <div class="button" onclick="$('#del').slideUp()">
        <?= getMessageByKey("general.no") ?>
      </div>
    </div>
  </div>
</form>


  <form action="?action=profgalvisusrhand" id="galform" method="post" style="margin-bottom: 50px;">
    <div class="usersettingsdiv">
      <div class="header">
        <?= getMessageByKey("user.settings.gallery") ?>
      </div>
      <div class="tr">
        <div class="td">
          <?= getMessageByKey("user.settings.gallery.show.ask") ?>
        </div>
        <div class="td">
          <select name="galvis">
            <option <?php
            if ($galVis == 1) {
              echo "selected";
            }
            ?> value="true"><?= getMessageByKey("general.yes") ?>
            </option>
            <option <?php
            if ($galVis == 0) {
              echo "selected";
            }
            ?> value="false"><?= getMessageByKey("general.no") ?>
            </option>
          </select>
        </div>
      </div>
      <div class="button" onclick="$('#galform').submit()">
        <?= getMessageByKey("button.general.continue") ?>
      </div>
    </div>
  </form>

</div>